package com.ruc.deke.controller;

import java.util.ArrayList;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruc.deke.dao.DBCourseDAO;
import com.ruc.deke.dao.TeacherDAO;
import com.ruc.deke.dao.UserDAO;
import com.ruc.deke.model.DBRecord;
import com.ruc.deke.utils.NotificationUtil;

/**
 * 统计图表相关数据接口
 * 
 * @author: cyj zzh
 * @date: 2017年5月20日 下午5:05:59
 */

@Controller
@RequestMapping(value = "/echart")
public class EchartController {

	@Resource(name = "userDAOImpl")
	private UserDAO userDAO;

	@Resource(name = "teacherDAOImpl")
	private TeacherDAO teacherDAO;

	@Resource(name = "dbCourseDAOImpl")
	private DBCourseDAO dbCourseDAO;

	@RequestMapping(value = "/test")
	@ResponseBody
	public void test(HttpSession session) {
		String email = "chengyijiandlmu@163.com";
		String subject = "MOOC";
		String body = "欢迎您注册！";
		NotificationUtil.sendEmail(email, subject, body);
	}

	/**
	 * 获取某学校专业班级的一批学生（某位老师负责）
	 * 
	 * @param session
	 * @return
	 * @author: cyj
	 * @date: 2017年4月1日 下午3:51:45
	 */
	@RequestMapping(value = "/getRealUsersByAno")
	@ResponseBody
	public ArrayList<DBRecord> getRealUsersByAno(HttpSession session) {
		String ano = session.getAttribute("ano").toString();
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.getRealUsersByAno(ano);
		return records;
	}

	/**
	 * 获取已经提交的人
	 * 
	 * @param session
	 * @param moduleId
	 * @return
	 * @author: cyj
	 * @date: 2017年4月4日 上午11:19:08
	 */
	@RequestMapping(value = "/haveSubmitedByAnoAndModule")
	@ResponseBody
	public ArrayList<DBRecord> haveSubmitedByAnoAndModule(HttpSession session, int moduleId) {
		String ano = session.getAttribute("ano").toString();
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.haveSubmitedByAnoAndModule(moduleId, ano);
		return records;
	}

	/**
	 * 获取已经提交的人以及答题信息
	 * 
	 * @param session
	 * @param moduleId
	 * @return
	 * @author: cyj
	 * @date: 2017年4月4日 上午11:19:08
	 */
	@RequestMapping(value = "/haveSubmitedAllByAnoAndModule")
	@ResponseBody
	public ArrayList<DBRecord> haveSubmitedAllByAnoAndModule(HttpSession session, int moduleId) {
		String ano = session.getAttribute("ano").toString();
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.haveSubmitedAllByAnoAndModule(moduleId, ano);
		return records;
	}

	/**
	 * 获取已经保存的人
	 * 
	 * @param session
	 * @param moduleId
	 * @return
	 * @author: cyj
	 * @date: 2017年4月4日 上午11:19:52
	 */
	@RequestMapping(value = "/haveSavedByAnoAndModule")
	@ResponseBody
	public ArrayList<DBRecord> haveSavedByAnoAndModule(HttpSession session, int moduleId) {
		String ano = session.getAttribute("ano").toString();
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.haveSavedByAnoAndModule(moduleId, ano);
		return records;
	}

	/**
	 * 获取某个教师负责范围内某个人的模块成绩
	 * 
	 * @param session
	 * @param moduleId
	 * @param userId
	 * @return
	 * @author: cyj
	 * @date: 2017年4月4日 下午10:25:13
	 */
	@RequestMapping(value = "getUserScoreByMoudleAndUserIdAndAno")
	@ResponseBody
	public ArrayList<DBRecord> getUserScoreByMoudleAndUserIdAndAno(HttpSession session, int moduleId, int userId) {
		String ano = session.getAttribute("ano").toString();
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.getUserScoreByMoudleAndUserIdAndAno(moduleId, userId, ano);
		return records;

	}

	/**
	 * 获取学生成绩列表
	 * 
	 * @param session
	 * @param moduleId
	 * @return
	 * @author: zzh
	 */
	@RequestMapping(value = "/getScoreByModuleAndAno")
	@ResponseBody
	public ArrayList<DBRecord> getScoreByModuleAndAno(HttpSession session, int moduleId) {
		String ano = session.getAttribute("ano").toString();
		ArrayList<DBRecord> records = new ArrayList<DBRecord>();
		records = userDAO.getScoreByModuleAndAno(ano, moduleId);
		return records;
	}

}
